#include "Udp_Server.hpp"
#include <memory>
#include <stdio.h>

//命令行参数手册
static void Usage(std::string proc)
{
    std::cout << "\nUsage:\n\t" << proc << " port\n" << std::endl; 
}

//小写转大写任务
std::string TransformAlpha(std::string str)
{
    std::string ret;
    for(auto& e : str)
    {
        if(islower(e))
        {
            ret += toupper(e);
        }
        else
        {
            ret += e;
        }
    }
    return ret;
}

//执行Linux指令
std::string ExecuteCommand(std::string command)
{
    FILE* fp = popen(command.c_str(), "r");
    if(fp == nullptr)
    {
        return "None";
    }

    char buff[1024];
    std::string ret;
    while(fgets(buff, sizeof(buff), fp) != nullptr)
    {
        ret += buff;
    }
    return ret;
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_FAIL);
    }
    //std::unique_ptr<UdpServer> up_user(new UdpServer(TransformAlpha, std::stoi(argv[1])));
    std::unique_ptr<UdpServer> up_user(new UdpServer(std::stoi(argv[1])));
    up_user->Start();
    return 0;
}